home *** CD-ROM | disk | FTP | other *** search
- /*
- % PUBLIC . C
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- This software is copyright (C) by the Lawrence Berkeley Laboratory.
- Permission is granted to reproduce this software for non-commercial
- purposes provided that this notice is left intact.
-
- It is acknowledged that the U.S. Government has rights to this software
- under Contract DE-AC03-765F00098 between the U.S. Department of Energy
- and the University of California.
-
- This software is provided as a professional and academic contribution
- for joint exchange. Thus, it is experimental, and is provided ``as is'',
- with no warranties of any kind whatsoever, no support, no promise of
- updates, or printed documentation. By using this software, you
- acknowledge that the Lawrence Berkeley Laboratory and Regents of the
- University of California shall have no liability with respect to the
- infringement of other copyrights by any part of this software.
-
- For further information about this notice, contact William Johnston,
- Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- (wejohnston@lbl.gov)
-
- For further information about this software, contact:
- Jin Guojun
- Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- g_jin@lbl.gov
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % initial & run time handlers (updating)
- % Including:
- % Button1_On(), SaveImage(), YesOrNo(), WaitOk(),
- % CreateTuner(), Set_Monitor(), histochange(),
- % ChangePanelCmap(), DrawPanel(), Get_Note_Input(),
- % DisplayMessage(),
- % Exposure_handler(), PickUpColor(), Toggle_Info(),
- % HistoHandle(), Histo_Setting(), Map_HistoWin(img)
- %
- % AUTHOR: Guojun Jin - LBL 4/1/1991
- */
-
- #ifndef RLE_IMAGE
- #define RLE_IMAGE
- #endif
-
- #ifndef Cursor_Flushing
- #define Cursor_Flushing 15
- #endif
-
- #include "tuner.h"
-
- bool rw_set, start_fast = 1; /* how to get system color */
- int fnt_r, fnt_g, fnt_b;
- PopMenu *ctrlmenu, *paramenu, *filemenu, *fontmenu;
- Panel *NoteWin, *InfoWin;
- Button *MsgButton;
- InterpMap *IM; /* interpolation matrix */
- PressButton *YesButt, *NoButt, *OkButt, *AbortButt;
- XWindowAttributes gwattrs;
- char *BN1[] = {"fore", "back", "linear"},
- *BNF[] = {"FILE", "Load", "Save"},
- *NF[] = {"OFF", "ON"},
- *HST[] = {"histogram", "Scale", "Set", "Neg", "Grid"},
- *DUP[] = {"Analysis", "Update"},
- *NOTEMSG[] = {"* CHANGE ETA SCALE *"};
-
- #ifndef HISTO_BACKGROUND
- #define HISTO_BACKGROUND lightGray
- #endif
-
- #define Dpy1 Monitor[1].dpy
- #define Screen1 Monitor[1].screen
-
- /*===============================================
- % public routines for color and b/w %
- ===============================================*/
- void
- Exposure_handler(expose, img)
- XExposeEvent *expose;
- Image *img;
- {
- register Window exp_win=expose->window;
- if (expose->type != Expose)
- return; /* generated by XCopyArea */
- if (img && exp_win == img->win)
- win_exposure(expose, img, (int(*)())Draws);
- else if (img && exp_win == img->icon)
- XPutImage(img->dpy, img->icon, img->igc, img->icon_image,
- 0, 0, 0, 0, img->icon_width, img->icon_height);
- else if (exp_win == Epanel->win)
- DrawPanel();
- else if (exp_win == InfoWin->win) Toggle_Info(0);
- else if (exp_win == histinfo.his->win)
- win_exposure(expose, histinfo.his, DrawVMark);
- else if (exp_win == NoteWin->win)
- DisplayMessage(NoteWin, NULL, 0, True);
- else message("strange exposure win %d\n", exp_win);
- DEBUGMESSAGE("expose event x= %d y= %d width= %d height= %d\n",
- expose->x, expose->y, expose->width, expose->height);
- }
-
- /*=======================================================
- % positive cquire to quire the colormap %
- % negtive cquire to quire user color table %
- =======================================================*/
- void
- dumpColor(dpy, cmap, cquire)
- Display *dpy;
- Colormap cmap;
- {
- XColor qcolor;
- register int i;
-
- if (!cquire) return;
- msg("colormap = %d\n", cmap);
- if (cquire>0)
- for (i=0; i < cquire; i++) {
- qcolor.pixel = (u_long) i;
- XQueryColor(dpy, cmap, &qcolor);
- message("vct[%3d]:(%3u) red =%8X, green =%8X, blue =%8X\n", i,
- qcolor.pixel, qcolor.red, qcolor.green, qcolor.blue);
- }
- else for (i=0; i<-cquire; i++)
- message("gtable[%3d]:(%3u) red =%8x, green =%8x, blue =%8x\n", i,
- graylevel[i].pixel, graylevel[i].red,
- graylevel[i].green, graylevel[i].blue);
- }
-
-
- void
- ChangeSlider(img, slider, s1, s2, equ_b, rel_b)
- Image *img;
- Slider **slider, *s1, *s2;
- Button *equ_b, *rel_b;
- {
- EraseSlider(*slider);
- switch (img->curve) {
- case ETAForeGD:
- case ETABackGD:
- *slider = s1; /* ESlider */
- SetSBarRPos(*slider, img->curve ? img->bgrd : img->fgrd, 1);
- break;
- case ETALinear:
- case ETALinear | ETAHistoEq:
- *slider = s2; /* LSlider */
- SetSBarRPos(*slider, img->linearlow, 1);
- SetSBarRPos(*slider, img->linearup, 2);
- ButtonState(equ_b /*heqButt*/) = img->curve & ETAHistoEq;
- break;
- default:msg("ETA %d\n", img->curve);
- }
- DrawSlider(*slider);
- SliderInfo(*slider, lightGray);
- ButtonState(rel_b) = img->curve & 0x7;
- DrawButton(rel_b); /* EButton */
- }
-
- void
- SetShowFramePos(img, f_b, reset)
- Image *img;
- Button *f_b;
- {
- sprintf(f_b->bname[PosFRAME], fb_format, img->fn+1, img->frames);
- if (reset) ButtonState(f_b)=RESETSTATE;
- DrawButton(f_b /*fButton*/);
- }
-
- SetPanelColor(dpy, cmap, cp, depth, fast)
- Display *dpy;
- Colormap cmap;
- XColor cp[];
- {
- if (fast>1) {
- Red = GetUserColor(cp, depth, 255, 0, 0);
- Green = GetUserColor(cp, depth, 0, 255, 0);
- Blue = GetUserColor(cp, depth, 0, 0, 255);
- Yellow = GetUserColor(cp, depth, 255, 255, 0);
- } else {
- Red = GetCloseColor(dpy, cmap, depth, NULL, 255, 15, 15);
- Green = GetCloseColor(dpy, cmap, depth, NULL, 15, 255, 20);
- Blue = GetCloseColor(dpy, cmap, depth, NULL, 15, 15, 255);
- Yellow = GetCloseColor(dpy, cmap, depth, NULL, 255, 255, 20);
- }
- if (Visible==darkGray) {
- Visible = GetGray(dpy, cmap, depth, 144);
- darkGray = GetGray(dpy, cmap, depth, 80);
- lightGray = GetGray(dpy, cmap, depth, 160);
- Gray = GetGray(dpy, cmap, depth, 192);
- }
- else Light = GetUserGray(cp, depth, 224);
-
- MGray = GetGray(dpy, cmap, depth, 96);
-
- if (verbose)
- fprintf(stderr, "[%d] greylevels %d\n\
- W=%d, Blk=%d, MG=%u LG=%u Gy=%u, Lt=%u; Y=%X, R=%X, G=%X, B=%X\n",
- cmap, ncolors, White, Black, MGray, lightGray, Light, Gray,
- Yellow, Red, Green, Blue);
- }
-
- /*=======================================================================
- % End of each line is always cut at a spcae except the word length %
- % exceeding line width, then a hyphen is added at broken place %
- =======================================================================*/
- void
- DisplayMessage(mw, msgsp, sp_limit, refresh)
- Panel *mw;
- char *msgsp;
- {
- int nl;
- register int i, ll, sp, sl=mw->width/mw->font_w-2, l, mp;
- char *sbuf = zalloc(sizeof(*sbuf), sl+2, "sbuf");
- static char* msgp;
- static int resp;
-
- if (!refresh)
- TopWindow(mw, 1),
- resp = sp_limit,
- msgp = msgsp; /* save current string */
- else if (!msgsp) /* use saved string */
- msgsp = msgp,
- sp_limit = resp;
-
- l = strlen(msgsp);
- for (i=mp=ll=0; mp < l; mp += ++nl) {
- nl = ((int)strchr(msgsp+mp, '\n') - (int)msgsp) - mp;
- if (nl<0 || nl>l)
- nl = l - mp;
- if (nl > sl) ll += nl / sl;
- ll++;
- }
- i = mw->height / mw->font_h;
- if (ll > i) ll = i;
- sp = (i - ll - 1) * mw->font_h / ll;
- if (sp_limit && sp > sp_limit)
- sp = sp_limit;
- if (sp > (mw->height>>2))
- sp = mw->font_h;
- XSetForeground(mw->dpy, mw->gc, white1);
- for (i=mp=0; i<ll; i++) {
- nl = ((int)strchr(msgsp+mp, '\n') - (int)msgsp) - mp + 1;
- if (i+1==ll) {
- l = strlen(msgsp+mp);
- if (l > sl) l = sl, ll++;
- }
- else if (nl<0 || nl>sl) l = sl;
- else l = nl;
- strncpy(sbuf, msgsp+mp, l); sbuf[l] = 0;
- if (i+1 != ll && (strchr(sbuf, ' ') || strchr(sbuf, '\n')))
- while (sbuf[l] != ' ' && sbuf[l] != '\n') l--;
- if (l)
- XDrawString(mw->dpy, mw->win, mw->gc,
- mw->font_w, (i+1)*(mw->font_h+sp), msgsp+mp, l);
- if (msgsp[mp+l] && msgsp[mp+l] != ' ' && msgsp[mp+l] != '\n')
- XDrawString(mw->dpy, mw->win, mw->gc,
- mw->font_w*(l+1), (i+1)*(mw->font_h+sp), "-", 1);
- else ++l;
- mp += l;
- }
- free(sbuf);
- XFlush(mw->dpy);
- }
-
- WaitOk(b, sp, line_h)
- PressButton* b;
- char* sp;
- {
- register XEvent *xe;
-
- if (!b) b = OkButt;
- xe = &b->pan->event;
-
- DisplayMessage(NoteWin, sp, line_h, 0);
- DrawPressButton(b);
- while (!XCheckMaskEvent(b->pan->dpy, ButtonPressMask, xe))
- if (XCheckMaskEvent(b->pan->dpy, ExposureMask, xe))
- Exposure_handler(xe, NULL), DrawPressButton(b);
- HidingPanel(NoteWin);
- return (b==OkButt);
- }
-
- YesOrNo(sp, line_h)
- char* sp;
- {
- register XEvent *xe = &YesButt->pan->event;
- register int state = 2;
-
- DisplayMessage(NoteWin, sp, line_h, 0);
- DrawPressButton(YesButt);
- DrawPressButton(NoButt);
- while (abs(state) >> 1) {
- while (!XCheckMaskEvent(YesButt->pan->dpy, ButtonPressMask, xe))
- if (XCheckMaskEvent(YesButt->pan->dpy, ExposureMask, xe))
- Exposure_handler(xe, NULL),
- DrawPressButton(YesButt),
- DrawPressButton(NoButt);
- if (ButtonPressed(YesButt, xe)) state = 1;
- else if (ButtonPressed(NoButt, xe)) state = 0;
- }
- HidingPanel(NoteWin);
- return state;
- }
-
- Get_Note_Input(buf, buf_size, sp_limit, info, i_color, dmsg)
- char *buf, *info;
- {
- DisplayMessage(NoteWin, buf, sp_limit, 0);
- if (info)
- DispInfo(NoteWin, 4, info, i_color);
- if (dmsg)
- DrawButton(MsgButton);
- buf[0] = 0;
- return TextLine(MsgButton, buf, buf_size,
- info ? (strlen(info)+1) * fontWidth : fontWidth,
- Exposure_handler, pic, num_images); /* only global usage */
- }
-
- void
- Toggle_Info(s)
- char *s;
- {
- static int state;
- static char* sp;
- register int old = !s;
-
- if (!old)
- sp = s;
- if (old || (state = !state))
- DisplayMessage(InfoWin, sp, 8, old);
- else HidingPanel(InfoWin);
- }
-
- void
- SetPanelItemColor()
- {
- Set_Panel(CSlider, SLIDER_COLOR, Green, Red, lightGray);
- Set_Panel(ESlider, SLIDER_COLOR, Blue, white1, Visible);
- Set_Panel(LSlider, SLIDER_COLOR, Red, white1, lightGray);
- Set_Panel(QSlider, SLIDER_COLOR, Red, Green, white1);
- Set_Panel(QButton, BUTTON_COLOR, Visible, Light, Green);
- Set_Panel(DButton, BUTTON_COLOR, Visible, Light, Green);
- Set_Panel(EButton, BUTTON_COLOR, lightGray, Yellow, Green);
- Set_Panel(FButton, BUTTON_COLOR, Visible, Light, Green);
- Set_Panel(fButton, BUTTON_COLOR, Visible, Light, Green);
- Set_Panel(hButton, BUTTON_COLOR, Visible, Light, Green);
- Set_Panel(Interpolate, BUTTON_COLOR, Visible, Light, Yellow);
- Set_Panel(ZButton, BUTTON_COLOR, Visible, Light, Yellow);
- Set_Panel(RstButt, PRESS_BUTTON_COLOR, Gray, lightGray, -1);
- Set_Panel(rfsButt, PRESS_BUTTON_COLOR, lightGray, Gray, Red);
- Set_Panel(heqButt, PRESS_BUTTON_COLOR, Light, lightGray, -1);
- Set_Panel(YesButt, PRESS_BUTTON_COLOR, Light, lightGray, -1);
- Set_Panel(NoButt, PRESS_BUTTON_COLOR, Light, lightGray, -1);
- ctrlmenu->bgcolor=paramenu->bgcolor=filemenu->bgcolor = Light; /*?*/
- }
-
- void
- ChangePanelCmap(img)
- U_IMAGE* img;
- {
- register int i=Dpy != Dpy1; /* point default cmap */
- if (i) return;
-
- XGetWindowAttributes(Epanel->dpy, Epanel->win, &gwattrs);
- if (gwattrs.colormap != img->colormap) {
- register int BaseGL=Monitor[i].cmap==img->colormap ? VCTEntry : 0;
- #ifdef _DEBUG_
- msg("\nsave colormap [%u] %X\n", firstmap, gwattrs.colormap);
- msg("gl77 = %05u %05u %05u\n",
- graylevel[77].red, graylevel[77].green, graylevel[77].blue);
- #endif
- if (gwattrs.colormap && firstmap)
- XStoreColors(Epanel->dpy, firstmap, graylevel, ncolors);
-
- for (i=img->entries; i--;)
- graylevel[i].pixel = i + BaseGL;
- XQueryColors(img->dpy, firstmap=img->colormap,
- graylevel, ncolors=img->entries);
- #ifdef _DEBUG_
- msg("new colormap = %X [%u]\n", img->colormap, firstmap);
- msg("gl77 = %05u %05u %05u\n",
- graylevel[77].red, graylevel[77].green, graylevel[77].blue);
- #endif
- XSetWindowColormap(Epanel->dpy, Epanel->win, firstmap);
- XSetWindowColormap(NoteWin->dpy, NoteWin->win, firstmap);
- XSetWindowColormap(InfoWin->dpy, InfoWin->win, firstmap);
- XSetWindowColormap(ctrlmenu->dpy, ctrlmenu->win, firstmap);
- XSetWindowColormap(paramenu->dpy, paramenu->win, firstmap);
- XSetWindowColormap(filemenu->dpy, filemenu->win, firstmap);
- XInstallColormap(Epanel->dpy, firstmap);
- if (ButtonState(QButton) && img->dpy_depth < 24) {
- Visible = darkGray;
- Light = GetGray(img->dpy, img->colormap, img->entries, 224);
- white1 = GetGray(img->dpy, img->colormap, img->entries, 248);
- SetPanelColor(img->dpy, img->colormap, graylevel, img->entries, 2);
- SetPanelItemColor();
- }
- }
- }
-
- PickUpColor(img, r, g, b)
- Image *img;
- int *r, *g, *b;
- {
- byte *p;
- int v=SetParameterWin(img, img->event, img->font_h, 0);
-
- DisplayMessage(NoteWin,
- "move mouse to choose a color\nrelease button to pick it up", 0, 0);
- while (!ImageEvent(img, ButtonReleaseMask))
- if (ImageEvent(img, PointerMotionMask))
- ParameterWin(img, &histinfo, img->event->xbutton.x,
- img->event->xbutton.y, v, False);
- v = img->width;
- p = img->data + img->channels * v * (img->event->xbutton.y
- #ifndef SCROLLBAR_on_CANVAS
- + img->y0) + img->x0 +
- #else
- ) +
- #endif
- img->event->xbutton.x;
- if (img->channels==1){
- v = *p;
- if (img->in_cmap)
- *r = img->in_cmap[0][v],
- *g = img->in_cmap[1][v],
- *b = img->in_cmap[2][v];
- }
- else {
- *r = *p;
- *g = p[v];
- *b = p[v << 1];
- v = (*r * RED_to_GRAY + *g * GREEN_to_GRAY + *b * BLUE_to_GRAY) >> 8;
- }
- HidingPanel(NoteWin);
- return v;
- }
-
- void
- MakeTrueColorPanel()
- {
- black1 = 0;
- white1 = 0xFFFFFF;
- gray1 = 0x808080;
- Red = 0x00FF;
- Green = 0x00FF00;
- Blue = 0xFF0000;
- Yellow = 0x00FFFF;
- Visible = 0x909090;
- darkGray = 0x505050;
- lightGray = 0xA0A0A0;
- Gray = 0xC0C0C0;
- Light = 0xE0E0E0;
- MGray = 0x606060;
- }
-
- void
- Set_Monitor(mnt, dpy, dpy1, cmap)
- WinAttribute* mnt;
- Display *dpy, *dpy1;
- Colormap cmap;
- {
- if (mnt == NULL)
- mnt = &Monitor[0];
- if (!dpy1)
- dpy1 = dpy;
- mnt->dpy = dpy;
- mnt->screen = XDefaultScreen(dpy);
- if (!cmap || dpy == dpy1)
- mnt->cmap = DefaultColormap(dpy, mnt->screen);
- else mnt->cmap = cmap;
- mnt->root = XDefaultRootWindow(dpy, mnt->screen);
- mnt->visual = XDefaultVisual(dpy, mnt->screen);
- mnt->dpy_depth = XDefaultDepth(dpy, mnt->screen);
-
- mnt++;
- mnt->dpy = dpy1;
- mnt->screen = XDefaultScreen(dpy1);
- if (!cmap || dpy != dpy1)
- cmap = DefaultColormap(dpy1, mnt->screen);
- mnt->cmap = cmap;
- mnt->root = XDefaultRootWindow(dpy1, mnt->screen);
- mnt->visual = XDefaultVisual(dpy1, mnt->screen);
- mnt->dpy_depth = XDefaultDepth(dpy1, mnt->screen);
-
- mnt--; /* always let Monitor[0] be color & Monitor[1] be mono */
- if (mnt->dpy_depth < mnt[1].dpy_depth) { /* if not, swap */
- register int tmp;
- mnt->dpy = dpy1;
- mnt[1].dpy = dpy;
- tmp = mnt->screen;
- mnt->screen = mnt[1].screen;
- mnt[1].screen = tmp;
- mnt[1].cmap = mnt->cmap;
- mnt->cmap = cmap;
- tmp = (int) mnt->root;
- mnt->root = mnt[1].root;
- mnt[1].root = (Window)tmp;
- tmp = (int) mnt->visual;
- mnt->visual = mnt[1].visual;
- mnt[1].visual = (Visual*) tmp;
- tmp = mnt->dpy_depth;
- mnt->dpy_depth = mnt[1].dpy_depth;
- mnt[1].dpy_depth = tmp;
- }
- if (ncolors > 1<<mnt->dpy_depth)
- ncolors = 1<<mnt->dpy_depth;
- }
-
- BuildImage(imgf, name, w, h, mfrm, IType, OType, IBflag)
- Image **imgf;
- char *name;
- {
- CreateImage(imgf, name, Monitor, w, h, StdIconWidth, I_Mask, IBflag);
- /* I_Mask | LeaveWindowMask */
- format_init(*imgf, IType, OType, -1, Progname, "A5-2");
- XDefineCursor((*imgf)->dpy, (*imgf)->win, cursor);
- XSetWindowBackground((*imgf)->dpy, (*imgf)->win, MGray);
- if (mfrm) {
- if ((*imgf)->marray) free((*imgf)->marray);
- (*imgf)->marray = zalloc(sizeof(Mregister), mfrm, "3m_array");
- }
- if ((*imgf)->data) free((*imgf)->data);
- (*imgf)->hist = (int*)nzalloc(HistoSize, sizeof(*(*imgf)->hist), "hist");
- XMapWindow((*imgf)->dpy, (*imgf)->frame);
- XMapWindow((*imgf)->dpy, (*imgf)->win);
-
- #ifdef EXTENDED_COLOR
- if ((*imgf)->dpy_depth != 8) {
- extern int log2_levels;
- register Image* i = *imgf;
- if (OType==HIPS)
- i->mono_img = True;
- if (!i->visual_class)
- i->visual_class = -1;
- i->lvls = 1 << (log2_levels=8);
- /* init_img_info(i, 0, OType, cmn_hd.color_dpy); */
- find_appropriate_visual(i);
- get_dither_colors(i);
- init_color(i); /* build dither array here */
- choose_scanline_converter(i);
- }
- #endif
- }
-
- CreateTuner(img, ela_scale, panel_bg, map_panel)
- U_IMAGE *img;
- PColor panel_bg;
- {
- register int i=1<<Monitor[1].dpy_depth, j;
-
- arrow = XCreateFontCursor(Dpy, XC_sb_down_arrow);
-
- #ifdef _DEBUG_
- message("%d graylevel\n", ncolors /* -(~newmap&VCTEntry) */);
- message("dpy=%x, dpy1=%x, screen=%d, screen1=%d\n", Dpy, Dpy1, Screen, Screen1);
- #endif
-
- /* must be after color allocated */
- if (!precision) precision = 384;
-
- if (img->dpy_depth < 24) {
- black1 = XBlackPixel(Dpy1, Screen1);
- white1 = gray1 = XWhitePixel(Dpy1, Screen1);
- if (i == 2) darkGray = i;
- SetPanelColor(Dpy1, Monitor[1].cmap, graylevel,
- MIN(i, ncolors), start_fast);
- }
- else MakeTrueColorPanel();
-
- if (panel_bg < 2)
- panel_bg = darkGray;
- if (x_regions < 2 || x_regions > MAX_ITP_LEVEL)
- x_regions = 2;
- if (y_regions < 2 || y_regions > MAX_ITP_LEVEL)
- y_regions = 2;
- i = MAX_ITP_LEVEL * MAX_ITP_LEVEL; /* taking 64K memory */
- j = MaxColors;
- IM = (InterpMap*)nzalloc(i, sizeof(*IM), "IM");
- while (i--)
- IM[i].lkt = (LKT*)nzalloc(j, sizeof(LKT), "lkts");
-
- lkt = histinfo.lkt = (LKT*)zalloc(j*(img->color_dpy?3:1), sizeof(*lkt), "lkt");
- if (img->color_dpy)
- for (i=0; i<MaxColors; i++)
- lkt[i] = lkt[j+i] = lkt[(j<<1)+i] = i;
-
- histinfo.hist = (int*)nzalloc(HistoSize, sizeof(*(histinfo.hist)), "hist");
- CreateImage(&(histinfo.his), "Histogram", Monitor, HistoSize+(BFRAME<<1),
- (HistoSize+(BFRAME<<1)) * (img->color_dpy ? 3 : 1), 32,
- I_Mask | ExposureMask, 1);
- histinfo.his->color_dpy = img->mid_type==RLE;
- histinfo.his->channels = img->dpy_channels ? img->dpy_channels : 1;
-
- XDefineCursor(Dpy, histinfo.his->win, arrow);
- XSetWindowBackground(Dpy, histinfo.his->win, MGray);
- XSelectInput(Dpy, histinfo.his->win, ExposureMask | I_Mask);
- return Panel_init(&Monitor[1], ela_scale, panel_bg, map_panel);
- }
-
- void
- DrawPanel()
- {
- /* it will be changed. */
- int pan_fgd = slider->pan->gc->values.foreground;
- DrawSlider(slider);
- DrawSlider(CSlider);
- DrawSlider(QSlider);
- DrawButton(EButton);
- DrawButton(FButton);
- DrawButton(fButton);
- DrawButton(hButton);
- DrawButton(ZButton);
- DrawButton(QButton);
- DrawButton(DButton);
- DrawButton(Interpolate);
- DrawPressButton(heqButt);
- DrawPressButton(rfsButt);
- DrawPressButton(RstButt);
- XSetForeground(slider->pan->dpy, slider->pan->gc, pan_fgd);
- }
-
- Button1_On(xbutton, fb)
- XButtonEvent *xbutton;
- int *fb;
- {
- if (ButtonPressed(RstButt, xbutton)) return OnResetButton;
- if (*fb=OnSliderBar(slider, xbutton)) return OnETASlider;
- if (*fb=OnSliderBar(CSlider, xbutton)) return OnClipSlider;
- if (*fb=OnSliderBar(QSlider, xbutton)) return OnQuanSlider;
- if (OnButton(hButton, xbutton)>0) return OnHistButton;
- if (OnButton(ZButton, xbutton)>0) return OnZcntButton;
- if (OnButton(QButton, xbutton)>0) return OnQuanButton;
- if (OnButton(fButton, xbutton)>0) return OnFrameButton;
- if (OnButton(EButton, xbutton)>0) return OnETAButton;
- if (OnButton(DButton, xbutton)>0) return OnDataButton;
- if (OnButton(Interpolate, xbutton)>0) return OnInterpolate;
- if (ButtonPressed(rfsButt, xbutton)) return OnRefresh;
- if (ButtonPressed(heqButt, xbutton)) return OnHEQButton;
- return EOF;
- }
-
-
- SaveImage(img)
- Image *img;
- {
- char buf[128];
- register int len;
-
- TopWindow(Epanel, 1);
- DrawPanel(); XFlush(Epanel->dpy);
- sprintf(buf, "SAVE %s before Close it ? y/n", img->name);
- len = (strlen(buf)+2) * Epanel->font_w;
- DispInfo(Epanel, 0, buf, white1);
- buf[0] = 0;
- TextLine(fButton, buf, sizeof(buf), len, Exposure_handler, pic, num_images);
-
- if (buf[0] != 'n'){
- ButtonState(FButton) = FileSave;
- FileAccess(&img, 1, 1);
- }
- }
-
- /*=======================================================
- % public histo_handle for both color and b/w %
- =======================================================*/
- void
- histchange(b, img, histinfo)
- Button *b;
- Image *img;
- HistoInfo *histinfo;
- {
- register int i;
- switch (ButtonState(b)) {
- case HistBgNeg: {
- register byte *hbp = histinfo->his->img_buf;
- i = histinfo->his->width * histinfo->his->height;
- for (; --i; hbp++)
- *hbp = -1 - *hbp;
- }
- XPutImage(histinfo->his->dpy, histinfo->his->win, histinfo->his->gc,
- histinfo->his->image, 0, 0,
- 0, 0, histinfo->his->width, histinfo->his->height);
- histinfo->neg = ~histinfo->neg;
- break;
- case HistBgGrid:
- if (histinfo->grids)
- histinfo->grids=0;
- else histinfo->grids=5; /* number of grids */
- HistoHandle(img, histinfo, HISTO_BACKGROUND);
- }
- }
-
- Histo_Setting(img, lbuf)
- U_IMAGE *img;
- char *lbuf;
- {
- register int i;
- if (ButtonState(hButton) > HistScaleSet)
- histchange(hButton, img, &histinfo);
- else {
- sprintf(lbuf, "maximum histo = %d, set %s", img->mmm.maxcnt,
- ButtonState(hButton)==HistScaleSelf ? "sacle" :
- "maximum value");
- i = (strlen(lbuf)+2) * Epanel->font_w;
- DispInfo(Epanel, 0, lbuf, white1);
- histinfo.scale = lbuf[0] = 0;
- TextLine(hButton, lbuf, sizeof(lbuf), i,
- Exposure_handler, pic, num_images);
- i = atoi(lbuf);
- img->setscale = ButtonState(hButton)==HistScaleSet;
- switch (ButtonState(hButton)){
- case HistScaleSelf:
- if (img->color_dpy)
- img->mmm.maxcnt = img->marray[img->fn %
- img->channels].maxcnt;
- else
- img->mmm.maxcnt = img->marray[img->fn].maxcnt;
- if (i) histinfo.scale = i;
- break;
- case HistScaleSet:
- if (i < 0) img->mmm.maxcnt = img->marray[0].maxcnt;
- else if (i>row) img->mmm.maxcnt = i;
- }
- HistoHandle(img, &histinfo, HISTO_BACKGROUND);
- }
- ButtonState(hButton) = RESETSTATE;
- DrawButton(hButton);
- }
-
- Map_HistoWin(img)
- U_IMAGE *img;
- {
- if (histinfo.map){
- XUnmapWindow(histinfo.his->dpy, histinfo.his->frame);
- histinfo.map = histinfo.his->sub_img = 0;
- }
- else {
- XMapWindow(histinfo.his->dpy, histinfo.his->frame);
- #ifdef SCROLLBAR_on_CANVAS
- XMapWindow(histinfo.his->dpy, histinfo.his->win);
- #endif
- histinfo.map = !histinfo.change;
- HistoHandle(img, &histinfo, HISTO_BACKGROUND);
- histinfo.change=histinfo.map=1;
- }
- }
-
- HistoHandle(img, hinfo, grid_color)
- Image *img;
- HistoInfo *hinfo;
- {
- static int last_channels;
- int channel, grid, grids, bground, border, bar, frac_grid, maxcnt,
- *newhist=(int*)zalloc(HistoSize*img->channels, sizeof(*newhist), "newhist");
- register int i, j, k, image_size, image_frame, *hp;
-
- if (hinfo->map){
- border = grid = grid_color;
- bground = HBGround;
- if (hinfo->neg) {
- border = grid = hinfo->neg - grid;
- bground = hinfo->neg - bground;
- }
- image_size=HistoSize, image_frame=HistoSize+(BFRAME<<1);
- if (hinfo->grids)
- grids = image_size / hinfo->grids;
- else grids = image_size;
- frac_grid = image_size % grids;
-
- for (channel=0; channel<img->channels; channel++) {
- {
- register LKT* lktp = (LKT*)hinfo->lkt + channel * HistoSize;
- register int *histp = hinfo->histp + channel * image_size;
- k = img->mmm.min; j = img->mmm.max - k + 1;
- for (i=0, hp=newhist + channel*HistoSize; i<j; i++)
- hp[lktp[i]] += histp[i+k];
- }
- if (img->setscale | img->color_dpy)
- maxcnt = img->mmm.maxcnt;
- else maxcnt = img->marray[img->fn].maxcnt;
- if (!maxcnt) maxcnt = 8192;
- #ifdef _DEBUG_
- if (verbose>1) dump_tbl(hp, image_size, 4, "hp");
- #endif
-
- if (img->channels == 1)
- bar = Green;
- else switch (channel) {
- case 0: bar = Red; break;
- case 1: bar = Green; break;
- case 2: bar = Blue;
- }
-
- if (img->dpy_depth == 8) {
- register byte* bhp = (byte*)hinfo->his->img_buf +
- channel*image_frame*image_frame;
- for (i=0; i<image_frame; i++)
- for (j=0; j<image_frame; j++)
- if (!j || j>=image_frame-BFRAME ||
- !i || i>=image_frame-BFRAME)
- *bhp++ = border;
- else if (!((i-frac_grid) % grids) || !(j % grids))
- *bhp++ = grid;
- else
- *bhp++ = bground;
- for (i=BFRAME; i<image_size+BFRAME; i++){ /* horizontal process */
- bhp = (byte*)hinfo->his->img_buf + i + image_frame *
- (channel * image_frame + image_size);
- j = (image_size * hp[i-BFRAME] << hinfo->scale) / maxcnt;
- if (j > image_size) j = image_size;
-
- for (k=0; k<j; k++) { /* vertical process */
- *bhp = bar;
- bhp -= image_frame;
- }
- }
- } else {
- register int* ihp = (int*)hinfo->his->img_buf +
- channel*image_frame*image_frame;
- for (i=0; i<image_frame; i++)
- for (j=0; j<image_frame; j++)
- if (!j || j>=image_frame-BFRAME ||
- !i || i>=image_frame-BFRAME)
- *ihp++ = border;
- else if (!((i-frac_grid) % grids) || !(j % grids))
- *ihp++ = grid;
- else
- *ihp++ = bground;
- for (i=BFRAME; i<image_size+BFRAME; i++) {
- ihp = (int*)hinfo->his->img_buf + i + image_frame *
- (channel * image_frame + image_size);
- j = (image_size * hp[i-BFRAME] << hinfo->scale) / maxcnt;
- if (j > image_size) j = image_size;
-
- for (k=0; k<j; k++) { /* vertical process */
- *ihp = bar;
- ihp -= image_frame;
- }
- }
- }
- }
- free(newhist);
- if (last_channels != img->channels)
- last_channels = img->channels,
- hinfo->his->resize_h = last_channels * 258,
- XResizeWindow(hinfo->his->dpy, hinfo->his->frame,
- image_frame, image_frame*img->channels);
- XPutImage(hinfo->his->dpy, hinfo->his->win, hinfo->his->gc, hinfo->his->image,
- 0, 0, 0, 0, image_frame, image_frame*img->dpy_channels);
- if (hinfo->his->sub_img)
- DrawVMark(hinfo->his, 0, 0);
- }
- XFlush(hinfo->his->dpy);
- hinfo->change=hinfo->map;
- }
-
- LineScan(p, scan, color, lktp, w, min, tc)
- register byte *p, *scan;
- register XColor *color;
- register LKT* lktp;
- register int w;
- {
- if (tc) while(w--)
- scan[w] = color[dgt[lktp[(p[w] - min)&0xFF]]].pixel;
- else while(w--)
- scan[w] = dgt[lktp[(p[w] - min)&0xFF]];
- }
-
- /* ANNOTATE an image by given colors */
- void
- RestoreArea(img, x, y, c, r, w, h)
- Image *img;
- {
- register int x0 = (x += c * w), y0 = (y += r * h);
- #ifndef SCROLLBAR_on_CANVAS
- x0 += img->x0; y0 += img->y0;
- #endif
- XPutImage(img->dpy, img->win, img->gc, img->image, x0, y0, x, y, w, h);
- }
-
- static int Acolor, Afont;
-
- Annotation(img, y0, keysym, stat)
- Image *img;
- int *y0;
- KeySym *keysym;
- XComposeStatus *stat;
- {
- int max_char, max_cinr, num_cols, num_rows, sp, x, y, len, fnt_w, fnt_h;
- char *buf = nzalloc(32, 32, "annotate");
- XEvent *event = img->event;
-
- if (img->dpy_depth > 8)
- return WaitOk(0, "no annotation on true color device", 0);
- Acolor = img->color_form==CFM_SCF ? CloseColor_in_Map
- (img->in_cmap, img->cmaplen, fnt_r, fnt_g, fnt_b, precision) :
- (RED_to_GRAY*fnt_r + GREEN_to_GRAY*fnt_g + BLUE_to_GRAY*fnt_b) >> 8;
- if (!img->color_dpy)
- Acolor >= 2;
- TopWindow(img, 0); Exposure_handler(event, img);
-
- while (1) {
- fnt_w = img->font_w, fnt_h = img->font_h;
- switch (WaitButtonPress_n_InfoImage(img, &histinfo, y0, arrow)) {
- case Button1:
- max_cinr = num_cols = num_rows = sp = 0;
- x = event->xbutton.x; y = event->xbutton.y;
- max_char = (img->width - x) / fnt_w;
-
- while (1) {
- FlushingCursor(img, Exposure_handler, &img, 1, x + num_cols*fnt_w,
- y+num_rows*fnt_h, fnt_w, 2, Cursor_Flushing, 1);
- if (!(len=XLookupString(event, buf+sp, 1024-sp, keysym, stat)))
- continue;
-
- buf[sp + len] = 0;
- if ((len=buf[sp]) == BS) {
- if (num_cols) {
- sp--; num_cols--;
- } else if (num_rows) {
- sp--; num_rows--;
- while((len=sp - num_cols) && buf[len-1] != CR)
- num_cols++;
- } else continue;
- RestoreArea(img, x, y-fnt_h, num_cols, num_rows, fnt_w, fnt_h);
- }
- else {
- if (++num_cols == max_char || len == CR) {
- if (buf[sp] != CR) {
- buf[sp+1] = buf[sp];
- buf[sp] = CR;
- }
- num_rows++;
- num_cols = 0;
- }
- if (max_cinr < num_cols)
- max_cinr = num_cols;
- if (len == Esc || len == CTRL_Y || ++sp >= 1024)
- break;
- else if (len != CR)
- XSetForeground(img->dpy, img->gc, Acolor),
- XDrawString(img->dpy, img->win, img->gc,
- x+(num_cols-1)*fnt_w, y+num_rows*fnt_h, buf+sp-1, 1);
- }
- }
- if (buf[sp] != CR) num_rows++;
- if (len != Esc)
- if (img->o_type==HIPS)
- superimpose_add_elem(img, buf, Acolor, -1,
- y, x, num_rows, max_cinr);
- else CombineImage_Draws(img, x, y, fnt_w*max_cinr, fnt_h*num_rows,
- Acolor);
- else RestoreArea(img, x, y-fnt_h, 0, 0, fnt_w * max_cinr,
- fnt_h * num_rows + XStringBaseHigh);
- break;
-
- case Button2:
- if ((len=GetNew_Img_Font(img)) < 0)
- Afont = len;
- else Acolor = len;
- break;
-
- case Button3:
- default: free(buf); return;
- }
- }
- }
-
- GetNew_Img_Font(img)
- Image *img;
- {
- int i = PopingMenu(fontmenu, MENUF_PKCOLOR, Exposure_handler, &img, 1);
-
- /* the list number in this popmenu is start from 0 rather 1 */
- if (--i < MENUF_1stFONT)
- if (i == MENUF_PKCOLOR)
- return PickUpColor(img, &fnt_r, &fnt_g, &fnt_b);
- else return i;
- else if (i < MENUF_UNDO)
- SetFontGetSize(img, fontlist[i]);
- return ~i;
- }
-
-
- WaitButtonPress_n_InfoImage(img, hinfo, y0, cursor)
- Image *img;
- HistoInfo *hinfo;
- int *y0;
- Cursor cursor;
- {
- /* clear previous button events */
- RemoveImageEvent(img, ButtonAction);
-
- *y0 = SetParameterWin(img, img->event, img->font_h, 0);
- XDefineCursor(img->dpy, img->win, cursor);
- while (!ImageEvent(img, ButtonPressMask)) {
- RemoveImageEvent(img, ButtonReleaseMask);
- if (ImageEvent(img, PointerMotionMask))
- ParameterWin(img, hinfo, img->event->xbutton.x,
- img->event->xbutton.y, *y0, False);
- while (ImageEvent(img, ExposureMask))
- Exposure_handler(img->event, img);
- }
- ClearParameterWin(img, *y0);
- return img->event->xbutton.button;
- }
-